package com.bryant.bryant_weather.splash

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.bryant.bryant_weather.MainActivity

import com.bryant.bryant_weather.R
import com.bryant.bryant_weather.storage.TokenPreferences
import com.bryant.bryant_weather.ui.login.LoginActivity

@SuppressLint("CustomSplashScreen")
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        // 在根视图加载完成后执行
        findViewById<View>(android.R.id.content).post {
            checkTokenAndRedirect()
        }
    }

    private fun checkTokenAndRedirect() {
        val token = TokenPreferences.getInstance(this).getToken()
        if (token.isNullOrEmpty()) {
            startActivity(Intent(this, LoginActivity::class.java))
            finish()
        } else {
            startActivity(Intent(this, MainActivity::class.java))
            finish()
        }
        finish()
    }
}